﻿using Microsoft.Office.Interop.Word;

namespace Songhay.Office2010.Word
{
    /// <summary>
    /// Extensions
    /// for <see cref="Microsoft.Office.Interop.Word.Application"/>
    /// </summary>
    public static partial class WordApplicationExtensions
    {
        /// <summary>
        /// Adds the Office Word key binding.
        /// </summary>
        /// <param name="style">The style.</param>
        /// <param name="word">The word.</param>
        /// <param name="category">The category.</param>
        /// <param name="command">The command.</param>
        /// <param name="key1">The key1.</param>
        /// <param name="key2">The key2.</param>
        /// <param name="commandParameter">The command parameter.</param>
        /// <remarks>
        /// For more detail, see “KeyBindings.Add Method”
        /// (http://msdn.microsoft.com/en-us/library/bb237125%28office.12%29.aspx)
        /// </remarks>
        public static void AddKeyBinding(this Style style,
            int key1, object key2 = null, object commandParameter = null)
        {
            WordApplicationUtility.AddKeyBinding(style.Application,
                WdKeyCategory.wdKeyCategoryStyle,
                style.NameLocal, key1, key2, commandParameter);
        }

        /// <summary>
        /// Sets the default text style.
        /// </summary>
        /// <param name="contentControl">The content control.</param>
        /// <param name="styleName">Name of the style.</param>
        public static void SetDefaultTextStyle(this ContentControl contentControl, string styleName)
        {
            var document = contentControl.Application.ActiveDocument;
            if(document == null) return;
            contentControl.set_DefaultTextStyle(document.Styles[styleName]);
        }
    }
}
